﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VVA.Data.Service;
using VVA.Website.UI.Helper;
using VVA.Website.UI.Models;

namespace VVA.Website.UI.Controllers
{
    public class NewsController : BaseController
    {
        //
        // GET: /News/
        [OutputCache(Duration = 360, VaryByParam = "slug")]
        public ActionResult Index(string slug)
        {
            var service = new ArticleService();
            var lst = service.GetAllByTaxonomySlug(slug, Culture);
            var model = new NewsCategoryDetailModel();

            model.Articles = lst;

            if (lst.Count() > 0)
            {
                model.TaxonomyName = lst.FirstOrDefault().TaxonomyName;
            }
            return View(model);
        }

        [OutputCache(Duration = 360, VaryByParam = "slug")]
        public ActionResult Detail(string slug)
        {
            var service = new ArticleService();
            var lst = service.GetAllByTaxonomySlug(slug, Culture);
            var model = new NewsCategoryDetailModel();

            model.Articles = lst;

            if (lst.Count() > 0)
            {
                model.TaxonomyName = lst.FirstOrDefault().TaxonomyName;
            }
            return View(model);
        }

        [OutputCache(Duration = 360, VaryByParam = "page")]
        public ActionResult Recruitment(int? page)
        {
            var service = new ArticleService();
            var lst = service.GetAllByTaxonomySlug("tuyen-dung", Culture);
            var model = new NewsCategoryDetailModel();

            model.Articles = lst;

            if (lst.Count() > 0)
            {
                model.TaxonomyName = lst.FirstOrDefault().TaxonomyName;
            }
            return View(model);
        }

        [OutputCache(Duration = 360, VaryByParam = "slug")]
        public ActionResult Read(string slug)
        {
            var service = new ArticleService();
            var model = service.GetBySlug(slug);

            return View(model);
        }

    }
}
